import App from './App'

// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'



Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
	...App
})
app.$mount()
// #endif

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'

//需要登录页面
const loginRequiredPaths = [
	'/pages/user/user',
	'/pages/order/list'
];

uni.addInterceptor('navigateTo', {
	invoke(args) {
		const url = args.url.split('?')[0]; // 去掉参数

		console.log("路由拦截", url);


		if (loginRequiredPaths.includes(url)) {

			let token = uni.getStorageSync("token");
			if (!token) {

				uni.navigateTo({
					url: '/pages/login/login'
				});
				return false;
			}

		}


		// if (loginRequiredPaths.includes(url)) {
		//   const token = uni.getStorageSync('token');
		//   if (!token) {
		//     uni.showToast({ title: '请先登录' });
		//     uni.navigateTo({ url: '/pages/login/login' });
		//     return false; // 终止跳转
		//   }
		// }
		return true;
	}
});

export function createApp() {
	const app = createSSRApp(App)
	return {
		app
	}
}
// #endif